<template>
  <el-col :span="22" :offset="1">
    <el-card>
      <el-table
        :data="commitlogs"
        style="width: 100%"
        max-height="370">
        <el-table-column
          fixed
          prop="sId"
          label="员工id"
          width="100">
        </el-table-column>
        <el-table-column
          prop="pId"
          label="项目id"
          width="100">
        </el-table-column>
        <el-table-column
          prop="cCreateTime"
          label="提交时间"
          width="150">
        </el-table-column>
        <el-table-column
          prop="cType"
          label="接收方"
          width="auto"
          :filters="[{text:'客户',value:'客户'},{text:'主管',value:'主管'}]"
          :filter-method="filterByPro">
        </el-table-column>
        <el-table-column
          prop="cFeedback"
          label="反馈意见"
          width="auto">
        </el-table-column>
        <el-table-column
          prop="cResponseType"
          label="反馈类型"
          width="100"
          :filters="[{text:'未处理',value:'未处理'},{text:'同意',value:'同意'},{text:'驳回',value:'驳回'}]"
          :filter-method="filterByPro">
        </el-table-column>
        <!--        <el-table-column-->
        <!--          prop="pType"-->
        <!--          label="项目类型"-->
        <!--          width="auto">-->
        <!--        </el-table-column>-->
        <el-table-column
          prop="cFileUrl"
          label="文件Url"
          width="200">
        </el-table-column>

        <el-table-column
          label=""
          width="auto">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleEdit(scope.$index,commitlogs)">编辑</el-button>
          </template>
        </el-table-column>

        <el-table-column
          label=""
          width="auto">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="deleteRow(scope.$index,commitlogs)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <template>
        <el-dialog title="修改提交信息"  width="40%" :visible.sync="dialogFormVisible">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item size="small" label="文件接受方">
              <template>
                <el-select v-model="form.cType" placeholder="请选择">
                  <el-option
                    v-for="item in c"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </template>
            </el-form-item>
            <el-form-item size="small" label="反馈意见">
              <el-input size="small" v-model="form.cFeedback"></el-input>
            </el-form-item>
            <el-form-item size="small" label="反馈类型">
              <template>
                <el-select v-model="form.cResponseType" placeholder="请选择">
                  <el-option
                    v-for="item in r"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </template>
            </el-form-item>
            <el-form-item size="small" label="文件Url">
              <el-input size="small" v-model="form.cFileUrl"></el-input>
            </el-form-item>
          </el-form>

          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取消</el-button>
            <el-button type="primary" @click="saveEdit">确认修改</el-button>
            <!--                <el-button type="primary" @click="dialogFormVisible = false">确认修改</el-button>-->
          </div>
        </el-dialog>
      </template>
    </el-card>

    <el-card style="margin-top: 10px">
      <el-button type="info" style="margin-left: 10px" @click="print">打印提交报表</el-button>
    </el-card>
  </el-col>
</template>

<script>
  import Global from '../../utils/global'
  var Type = [' ','主管','客户']
  var ResponseType = ['未处理','同意','驳回']
  export default {
    name: 'CommitManageSuper',
    data(){
      return{
        idx:-1,
        form:{
          sId:null,
          pId:null,
          cCreateTime: null,
          cType: null,
          cFeedback:null,
          cResponseType: null,
          cFileUrl: null,
        },
        input4search:'',
        glo:new Global,
        commitlogs: [],
        dialogFormVisible: false,
        c:[{
          value:1,
          label:'主管',
        },{
          value:2,
          label:'客户',
        }],
        r:[{
          value:0,
          label:'未处理',
        },{
          value:1,
          label:'同意',
        }, {
          value:2,
          label: '驳回',
        }]
      }
    },
    methods:{
      print(){
        var timestamp = (new Date()).valueOf();
        var token = md5("epms" + timestamp);
        window.open("http://47.92.227.185:8080/download/commitLogCsv?token="+token+"&timestamp="+timestamp)
        // var data = {}
        // this.glo.sendDate(this.glo.server+'download/wageCsv',data,null,"POST")
      },
      deleteRow(index, commitlogs) {
        this.idx = index;
        var data = commitlogs[index]
        this.glo.sendDate(this.glo.server + "super/delProject", data, this.handleResDel,"POST")
      },

      filterByPro(value, row, column){
        const property = column['property'];
        return row[property] === value;
      },
      handleEdit(index,commitlogs) {
        this.idx = index;
        this.form = commitlogs[index];
        this.dialogFormVisible = true;
        // this.glo.sendDate(this.glo.server + "frontDesk/getAllClient", data, this.handleRes,"POST")
      },
      saveEdit() {
        this.commitlogs[this.idx] = this.form;
        var commitlog = this.form
        this.glo.sendDate(this.glo.server + "super/updateProjectInfo", commitlog, this.handleResEdit,"POST")
        this.dialogFormVisible = false;
        console.log(this.commitlogs)
      },
      handleResEdit(res){
        console.log(res)
        let feedBack = eval(res);
        console.log(feedBack)
        if (feedBack.code == 20000) {
          this.$message.success(`第 ${this.idx + 1} 行记录修改成功`);
        }else{
          this.$message.error(`修改失败`);
          location.reload()
        }
      },

      inserTable (line) {
        this.commitlogs.push(
          {
            sId: line.sId,
            pId:line.pId,
            cCreateTime:line.cCreateTime,
            cType:Type[line.cType],
            cFeedback:line.cFeedback,
            cResponseType:ResponseType[line.cResponseType],
            cFileUrl:line.cFileUrl,
          }
        )
      },
      initCommitLogPage (res) {
        console.log(res)
        for (var line in res.data.commitLogList){
          this.inserTable(res.data.commitLogList[line])
        }
        console.log(this.tableData)

      },
      handleRes (res) {
        console.log(res);
        let feedBack = eval(res);
        if (feedBack.success == false) {//登录失败
          this.$message("提交列表获取失败");
          return;
        }
        this.$message.success("提交列表获取成功^^")
        this.initCommitLogPage(feedBack)
      },
    },
    mounted(){
      let data = {
        sId:JSON.parse(sessionStorage.getItem('StaffInfo')).sId
      }
      this.glo.sendDate(this.glo.server+'admin/getAllCommitLog',data,this.handleRes,"POST")
    },
  }
</script>

<style scoped>

</style>
